<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<div id="classManagerGrid"></div>
<div id="classManagerToolbar">
	<div>
		<a href="#" class="easyui-linkbutton" onclick="classManager.toolbar.showAddDialog();" data-options="
		iconCls:'icon-add',
		plain:true">
			新增
		</a>
		<a href="#" class="easyui-linkbutton" onclick="classManager.toolbar.showUpdateDialog();" data-options="
		iconCls:'icon-edit',
		plain:true">
			修改
		</a>
		<a href="#" class="easyui-linkbutton" onclick="classManager.toolbar.remove();" data-options="
		iconCls:'icon-remove',
		plain:true">
			删除
		</a>
		<a href="#" class="easyui-linkbutton" onclick="classeses.toolbar.showAddDialog();" data-options="
		iconCls:'icon-lock-open',
		plain:true">
			启用
		</a>
		<a href="#" class="easyui-linkbutton" onclick="classeses.toolbar.showAddDialog();" data-options="
		iconCls:'icon-locks',
		plain:true">
			禁用
		</a>
		<a href="#" class="easyui-linkbutton" onclick="classManager.toolbar.redo();" data-options="
		iconCls:'icon-redo',
		plain:true">
			取消
		</a>
	</div>
	<div>
		<strong>班级名称：</strong>
		<input type="text" name="name" id="searchName" class="easyui-textbox"/>
		<strong>状态：</strong>
		<select name="state" id="searchState" class="easyui-combobox" style="width:100px;height:23px">
			<option value="">全部</option>
			<option value="1">启用</option>
			<option value="2">禁用</option>
		</select>
		<strong>创建时间：</strong>
		<input type="text" name="operateTime" id="searchTime" class="easyui-datetimebox"/>
		<a href="#" onclick="classManager.toolbar.search()" class="easyui-linkbutton" data-options="
		iconCls:'icon-search',
		plain:true">
			查询
		</a>
	</div>
</div>

<div id="classManagerAddDialog" style="width:320px" class="easyui-dialog classManager-add" data-options="
title:'新增班级',
buttons:'#classManagerAddButtons',
closed: true,
onClose:classManager.toolbar.resetAddFrom">
	<form id="classManagerAddForm" method="post">
			<p style="margin-top:10px">
				<strong>班级名称:</strong>
				<input type="text" name="name" class="easyui-textbox" style="width:80%;height:30px" data-options="
				required: true">
			</p>
			<p style="margin-top:10px">
				<strong>课程编号:</strong>
				<input type="text" name="courseId" class="easyui-textbox" style="width:80%;height:30px" data-options="
				required: true">
			</p>
			<input type="hidden" name="operateUserId" value="${sysUser.id}">
			<p style="margin-top:10px">
				<strong>创建时间:</strong>
				<input type="text" name="operateTime" class="easyui-datetimebox" style="width:80%;height:30px">
			</p>
			<input type="hidden" name="state" value="1">
			<p style="margin-top:10px">
				<!-- <strong>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</strong>-->
				<input type="hidden" name="memo">
			</p>
	</form>
</div>
<div  id="classManagerAddButtons" style="margin-top:5px">
	<a href="#" onclick="classManager.toolbar.add()" class="easyui-linkbutton" style="width:30%;height:30px;margin-right:50px" data-options="
	iconCls:'icon-ok',
	plain: true">新增</a>
	<a href="#" onclick="classManager.toolbar.hiddenAddDialog()" class="easyui-linkbutton" style="width:30%;height:30px;margin-right:10px" data-options="
	iconCls:'icon-redo',
	plain: true">取消</a>
</div>

<div id="classManagerUpdateDialog" style="width:320px;" class="easyui-dialog classManager-add" data-options="
title: '修改班级信息',
buttons: '#classManagerUpdateButtons',
closed: true,
onClose: classManager.toolbar.resetUpdateFrom">
	<form id="classManagerUpdateForm" method="post">
			<input type="hidden" name="id"/>
			<p style="margin-top:10px">
				<strong>班级名称:</strong>
				<input type="text" name="name" class="easyui-textbox" style="width:80%;height:30px" data-options="
				required: true">
			</p>
			<p style="margin-top:10px">
				<strong>课程编号:</strong>
				<input type="text" name="courseId" class="easyui-textbox" style="width:80%;height:30px" data-options="
				required: true">
			</p>
			<p style="margin-top:10px">
				<strong>状&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;态:</strong>
				<select name="state" class="easyui-combobox" style="width:80%;height:30px">
					  <option value="1">启用</option>
					  <option value="2">禁用</option>
				</select>
			</p>
			<p style="margin-top:10px">
				<!-- <strong>备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注:</strong>-->
				<input type="hidden" name="memo">
			</p>
	</form>
</div>
<div id="classManagerUpdateButtons" style="margin-top:5px">
	<a href="#" onclick="classManager.toolbar.update()" style="width:30%;height:30px;margin-right:50px" class="easyui-linkbutton" data-options="
	iconCls: 'icon-edit',
	plain: true">
		修改
	</a>
	<a href="#" onclick="classManager.toolbar.hiddenUpdateDialog();" style="width:30%;height:30px;margin-right:10px" class="easyui-linkbutton" data-options="
	iconCls: 'icon-redo',
	plain: true">
		取消
	</a>
</div>

<script>	
	var classManager = {
		init : function() {
			classManager.classManagerGrid = $('#classManagerGrid');
			classManager.classManagerAddDialog = $('#classManagerAddDialog');
			classManager.classManagerAddForm = $('#classManagerAddForm');
			classManager.classManagerUpdateForm = $('#classManagerUpdateForm');
			classManager.classManagerUpdateDialog = $('#classManagerUpdateDialog');
			classManager.classManagerSearchName = $('#searchName');
			
			classManager.classManagerGrid.datagrid({
			    url: '<%=request.getContextPath()%>/ClassManagerServlet?command=listClassManager',
			    fixed: true,
			    fitColumns: true,
			    striped: true,
			    rownumbers: true,
			    pagination: true,
			    pageSize: 10,
			    pageList: [10, 20, 30, 40, 50],
			    pageNumber: 1,
			    sortName: 'cl.operate_time',
			    sortOrder: 'desc',
			    toolbar: '#classManagerToolbar',
			    columns:[[
					{field:'id', checkbox: true},
					{field:'name', title:'班级名称', width:100, align:'center'},
					{field:'course__name', title:'关联课程', width:50, align:'center', sortable: true},
					{field:'operateTime', title:'创建时间', width:100, align:'center'},
					{field:'stateStr', title:'状态', width:100, align:'center'},
					]],
				onDblClickRow: function(rowIndex, rowData) {
					classManager.toolbar.showUpdateDialog(rowData.id);
				}
			});
		},
		toolbar: {
			showAddDialog: function() {
				classManager.classManagerAddDialog.dialog('open');
			},
			hiddenAddDialog: function() {
				classManager.classManagerAddDialog.dialog('close');
				classManager.toolbar.resetAddForm();
			},
			resetAddForm: function() {
				classManager.classManagerAddForm.form('reset');
			},
			add: function() {
				if (classManager.classManagerAddForm.form('validate')) {
					
					$.post('<%=request.getContextPath()%>/ClassManagerServlet?command=addClassManager', classManager.classManagerAddForm.serialize(), function(data) {
						classManager.toolbar.hiddenAddDialog();
						if (data) {
							$.messager.show({
								title: '系统提示',
								msg: '新增成功！',
								timeout: 3000,
								showType: 'slide'
							});
							classManager.toolbar.resetAddFrom();
							classManager.classManagerGrid.datagrid('reload');
						} else {
							$.messager.alert('系统提示', '新增失败！', 'error')
						}
						classManager.toolbar.hiddenAddDialog();
					});
				}
			},
			showUpdateDialog: function(id) {
				var getData = function(v) {
					$.post('<%=request.getContextPath()%>/ClassManagerServlet?command=getClassManager', {id : v}, function(data) {
						if (data) {
							classManager.classManagerUpdateForm.form('load', {
								id: data.id,
								name: data.name,
								courseId: data.courseId,
								state: data.state,
								memo: data.memo
							});
							classManager.classManagerUpdateDialog.dialog('open');
						} else {
							$.messager.alert('系统提示', '获取信息失败！', 'error')
						}
						$.messager.progress('close');
					}, 'json');
				}
				if (id) {
					getData(id);
				} else {
					var row = classManager.classManagerGrid.datagrid('getSelections');
					if (row.length == 1) {
						getData(row[0].id);
					} else {
						$.messager.show({
							title: '系统提示',
							msg: '请选择一行数据进行修改！',
							timeout: 3000,
							showType: 'slide'
						});	
					}
				}
			},
			hiddenUpdateDialog: function() {
				classManager.classManagerUpdateDialog.dialog('close');
				classManager.toolbar.resetUpdateFrom();
			},
			resetUpdateFrom: function() {
				classManager.classManagerUpdateForm.form('reset');
			},
			update: function() {
				if (classManager.classManagerUpdateForm.form('validate')) {
					$.post('<%=request.getContextPath()%>/ClassManagerServlet?command=updateClassManager', $("#classManagerUpdateForm").serialize(), function(data) {
						if (data == 1) {
							$.messager.show({
								title: '系统提示',
								msg: '修改成功！',
								timeout: 3000,
								showType: 'slide'
							});
							classManager.toolbar.resetUpdateFrom();
							classManager.classManagerGrid.datagrid('reload');
						} else {
							$.messager.alert('系统提示', '修改失败！', 'error');
						}
						
						classManager.toolbar.hiddenUpdateDialog();
					});
				}
			},
			remove: function() {
				var row = classManager.classManagerGrid.datagrid('getSelections');
				if (row.length > 0) {
					var ids = [];
					$.each(row, function(i, v) {
						ids.push(v.id);
					});
					$.post('<%=request.getContextPath()%>/ClassManagerServlet?command=deleteClassManager', {ids: ids.join(',')}, function(data) {
						if (data == 1) {
							$.messager.show({
								title: '系统提示',
								msg: '删除成功！',
								timeout: 3000,
								showType: 'slide'
							});
							classManager.classManagerGrid.datagrid('reload');
						} else {
							$.messager.alert('系统提示', '删除失败！', 'error')
						}
						$.messager.progress('close');
					});
				} else {
					$.messager.show({
						title: '系统提示',
						msg: '请选择数据进行删除！',
						timeout: 3000,
						showType: 'slide'
					});	
				}
			},
			redo: function() {
				classManager.classManagerGrid.datagrid('unselectAll');
			},
			search: function() {
				classManager.classManagerGrid.datagrid('load', {
					name: classManager.classManagerSearchName.val(),
					//state: classManager.classManagerSearcState.val(),
					//operateTime: classManager.classManagerSearchTime.val()
				});
			}
		},
	};
	
	$(function(){
		classManager.init();
	});
</script>
